package edu.siu.math.egut.main;

import java.io.IOException;

import edu.siu.math.egut.io.LiE;
import edu.siu.math.egut.io.OutputPref;
import edu.siu.math.egut.util.Polynomial;
import edu.siu.math.egut.util.PolynomialReadException;

/**
 * DCA stands for Double Coset Analysis.  For a detailed description of the set up see 
 * the EGUT program DCA.  
 * 
 * As described in the javadoc for DCA, 
 * "We need to analyze P1\M/S.  One may show that every element contains a representative of the 
 * form nu0 delta, where nu0 is an element of N_M(T) representing an element of W(M,T) which 
 * is of minimal length in W(M1, T)\W(M,T)/W(M_psi, T), and delta is an element on N_{nu0}."
 * 
 * However, it is not at all unlikely that W(M1, T)\W(M,T)/W(M_psi, T) is
 * actually much larger than P1\M/S.  Perhaps in a particular example of interest
 * one can show by other means that it suffices to analyze elements nu0 from a much
 * shorter list.  In this case, one will wish to use this program, and simply enter the 
 * Weyl elements nu0 manually.

 * 
 * @author Joseph Hundley
 *
 */
public class DCA_Weyl {
    private static final OutputPref ERR = OutputPref.ERR;
    private static final OutputPref SHOW=OutputPref.SHOW;
    @SuppressWarnings("unused")
    private static final OutputPref HIDE = OutputPref.HIDE;
    private static LiE lie = new LiE();

    /**
     * @param args parabolic P, parabolic Q, polynomial psi, parabolic P2 of the Levi of P, name of exceptional group 
     */
    public static void main(final String[] args) {
	
	if( args.length <4){
	    System.out.print("Not enough information.  Need:\n " +
	    		"\t* Parabolic P, such that the Fourier coefficient is taken along the \n\tunipotent radical of P,\n" +
	    		"\t* Parabolic Q, such that Eisenstein is induced from Q,\n" +
	    		"\t* a polynomial psi factor,\n" +
	    		"\t* weyl Element nu0\n" +
	    		"\t* group G\n" +
	    		"Parabolics should be specified by listing the simple roots in the\n" +
	    		"unipotent radical.\n" +
	    		"Example: [2] [1] u11222221+u22343210 [1,2,3,4] E8\n");
	    System.exit(1);
	    
	}
	
	
	final String pString =args[0];
	final String qString = args[1];
	
	Polynomial psi = Polynomial.create(1);
	    try {
		psi = Polynomial.read(args[2]);
	    } catch (final PolynomialReadException e1) {
		System.out.println("Problem reading psi.");
		e1.printStackTrace();
		System.exit(1);
	    }
	final String nu0String = args[3];
	final String groupName = args[4];
	
	
	
	    
	try {
	    
	    
	    
		// set default group   
	    lie.exec( "setdefault "+groupName, ERR);
	    lie.exec("p = "+pString, ERR);
	    lie.exec("q="+qString, ERR);
	    // get w0.
	    lie.exec("w0 = lr_reduce(complement("+qString+"),long_word, complement("+pString+"))", ERR);
	    DCA.say("Long element of Q\\G/P (denote by w0)");
	    lie.exec("w0",SHOW);
	    DCA.say("w0^{-1}Qw0 \\cap M(P)");
	    lie.exec( "p1=complement(complement(p), levi_para( w0,"+qString+","+pString+"))", ERR);
	    lie.exec("p1", SHOW);
	    DCA.say("nu0 = "+nu0String);
	DCA.analyze( nu0String, pString, qString, psi, lie);

	    
	} catch (final IOException e) {
	    System.out.println("Problem starting LiE.");
	    e.printStackTrace();
	    System.exit(1);
	} catch (final Exception e) {
	    System.out.println("Exception encountered.  Possible cause:  problem reading LiE output.");

	    e.printStackTrace();
	}
	
	
    }// end main



    
    
}// end class
